package main.java;

import java.util.Arrays;
import java.util.List;

/**
 * @program: pratice
 * @author: 关键我是大怪
 * @create: 2021-10-03 15:56
 */
public class Test48_最小时间差 {
    public int findMinDifference(List<String> timePoints) {
        int ans = 720;
        int n = timePoints.size();
        int[] sum = new int[n];
        for (int i = 0; i < timePoints.size(); i++) {
            int a = Integer.parseInt(timePoints.get(i).split(":")[0]);
            int b = Integer.parseInt(timePoints.get(i).split(":")[1]);
            sum[i] = a * 60 + b;
        }

        Arrays.sort(sum);
        int pre = sum[0];
        int first = sum[0];
        for (int i = 1; i < n; i++) {
            ans = Math.min(ans, Math.min(sum[i] - pre, 1440 - sum[i] + first));
            pre = sum[i];
        }
        return ans;
    }
}
